﻿using AuthCenter_HuangJingtao.Domain;
using AuthCenter_HuangJingtao.ErrorCode;
using AuthCenter_HuangJingtao.Infrastructure.Imterfaces;
using AuthCenter_HuangJingtao.Read.Api.Application.Command.MenuaLL;
using MediatR;
using Microsoft.EntityFrameworkCore;

namespace AuthCenter_HuangJingtao.Read.Api.Application.CommandHandler.MenuaLL
{
    public class ShowMenuCommandHandler : IRequestHandler<ShowMenuCommand, ApiResult<List<Menus>>>
    {
        IBaseReponsitory<Menus> Menus;

        public ShowMenuCommandHandler(IBaseReponsitory<Menus> Menus)
        {
            this.Menus = Menus;
        }

        public async Task<ApiResult<List<Menus>>> Handle(ShowMenuCommand request, CancellationToken cancellationToken)
        {
            
            var list = await Menus.GetQuery().Where(c=>!c.Menu_IsDel).ToListAsync();
            return new ApiResult<List<Menus>> 
            {
                Code = ApiEnum.Success,
                Message = "查询成功",
                Data = list
            };
        }
    }
}
